package com.sangeng.controller;

import com.sangeng.domain.ResponseResult;
import com.sangeng.domain.vo.ArticleDetailVo;
import com.sangeng.domain.vo.HotArticleVo;
import com.sangeng.domain.vo.PageVo;
import com.sangeng.service.ArticleService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author li-siyu
 */
@RestController
@RequestMapping("/article")
@RequiredArgsConstructor
public class ArticleController {

    /**
     * 修改为构造器注入
     *
     * @Autowired private ArticleService articleService;
     */
    private final ArticleService articleService;

    @GetMapping("/hotArticleList")
    public ResponseResult<List<HotArticleVo>> hotArticleList() {
        //查询热门文章 封装成ResponseResult返回
        return articleService.hotArticleList();
    }

    @GetMapping("/articleList")
    public ResponseResult<PageVo> articleList(Integer pageNum, Integer pageSize, Long categoryId) {
        //(首页和分类下面点进去的详情页)查询文章列表 封装成ResponseResult返回
        return articleService.articleList(pageNum, pageSize, categoryId);
    }

    @GetMapping("/{id}")
    public ResponseResult<ArticleDetailVo> getArticleDetail(@PathVariable("id") Long id) {
        //获取文章详情
        return articleService.getArticleDetail(id);
    }

    @PutMapping("/updateViewCount/{id}")
    public ResponseResult<String> updateViewCount(@PathVariable("id") Long id) {
        return articleService.updateViewCount(id);
    }
}
